from start_appium import get_driver
from time import sleep
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import sys
sys.path.append("D:/test/Appium2021")
# from util.read_int import ReadIni
from util.get_by_local import GetByLocal

def go_by_uiautomatot_login():
    print(driver.find_element_by_android_uiautomator('new UiSelector().text("点击登录")'))
    driver.find_element_by_android_uiautomator('new UiSelector().text("点击登录")').click() # 匹配全部text文字
def login_phone():
    driver.find_element_by_android_uiautomator('new UiSelector().text("手机号码")').click()
    # xpath定位元素手机号码输入框
    el1 = driver.find_element_by_xpath(
        "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[3]/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.EditText")
    el1.clear()
    el1.send_keys("18559651669")
    # driver.find_element_by_android_uiautomator('new UiSelector().text("请填写手机号码")').send_keys("18559651669")
    sleep(1)
    driver.find_element_by_android_uiautomator('new UiSelector().text("下一步")').click()
    # 定位元素手机密码输入框
    el3 = driver.find_element_by_xpath(
        "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.EditText")
    el3.send_keys("123456")
    driver.find_element_by_android_uiautomator('new UiSelector().text("登录")').click()

def login_by_class():
    element = driver.find_element_by_class_name('android.widget.Button')
    print(element)
    element.click()
    elements =len(driver.find_elements_by_class_name('android.widget.Button'))
    # elements[1].click()
    print(elements)
    #一般class_name都有重复的
#层级定位
def login_by_node():
    element = driver.find_element_by_id('android:id/content')
    elements = element.find_elements_by_class_name('android.widget.Button')
    elements[0].click()

def get_tost():
    el1 = driver.find_element_by_xpath(
        "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[3]/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.EditText")
    el1.clear()
    driver.find_element_by_android_uiautomator('new UiSelector().text("下一步")').click()
    tost_element = ("xpath","//*[contains(@text,'手机号码不能为空')]")
    print(WebDriverWait(driver,10,0.1).until(EC.presence_of_element_located(tost_element)))

def login():
    get_by_local = GetByLocal(driver)
    get_by_local.get_element('login_button').click()

    # login_button = read_int.get_value("login_button")
    # driver.find_element_by_class_name(login_button).click()
def go_my():
    get_by_local = GetByLocal(driver)
    get_by_local.get_element("my","my_element").click()

driver = get_driver()
# login()
go_my()
# go_by_uiautomatot_login()
# get_tost()
# login_by_class()
# go_login()
# login_phone()